from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys

# 实例化浏览器驱动
driver = webdriver.Chrome()
# 最大化浏览器
driver.maximize_window()
# 打开百度
driver.get("https://www.baidu.com")
time.sleep(2)

# # 定位百度一下按钮
# baidu_button = driver.find_element(By.ID, "su")
# # 存储动作链,右击
# action_1 = ActionChains(driver).context_click(baidu_button)
# # 执行动作链
# action_1.perform()

# # 双击
# ActionChains(driver).double_click(baidu_button).perform()
# 悬停

# # 鼠标悬停到【设置】按钮，下拉展开
# ActionChains(driver).move_to_element(driver.find_element(By.ID, "s-usersetting-top")).perform()

input_ele = driver.find_element(By.ID, "kw")
# 输入-坚果
input_ele.send_keys("坚果")
time.sleep(1)
# 删除-果
input_ele.send_keys(Keys.BACK_SPACE)
time.sleep(1)
# 输入-空格
input_ele.send_keys(Keys.SPACE)
time.sleep(1)
# 输入python
input_ele.send_keys("python")
time.sleep(1)
# 全选
input_ele.send_keys(Keys.CONTROL, "a")
time.sleep(1)
# 剪切
input_ele.send_keys(Keys.CONTROL, "x")
time.sleep(1)
# 粘贴5次
for i in range(5):
    input_ele.send_keys(Keys.CONTROL, "v")
    time.sleep(1)
time.sleep(5)
driver.quit()